﻿/*  ----------------------------------------------------------------------------
 *  Author:
 *  Chandra Shekhar Tripathi
 *  ----------------------------------------------------------------------------
 *  Product Name:
 *  DbDocumenter
 *  ----------------------------------------------------------------------------
 *  Year:
 *  2009
 *  ----------------------------------------------------------------------------
 *  File:
 *  SQLDBInfoManager.cs
 *  ----------------------------------------------------------------------------
 */
namespace DBDocumenter.BLL.Services.SQL
{
    using System;
    using System.Collections.Generic;

    using DBDocumenter.BLL.Entities;
    using DBDocumenter.DAL.SQL;
    using DBDocumenter.Exception;

    /// <summary>
    /// 
    /// </summary>
    public class SQLDBInfoManager
    {
        #region Fields

        private static SQLDBInfoManager instance = new SQLDBInfoManager();

        #endregion Fields

        #region Properties

        /// <summary>
        /// Gets or sets the instance.
        /// </summary>
        /// <value>The instance.</value>
        public static SQLDBInfoManager Instance
        {
            get { return SQLDBInfoManager.instance; }
            set { SQLDBInfoManager.instance = value; }
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Gets the databases.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <returns></returns>
        public List<ServerInfo> GetDatabases(string connectionString)
        {
            try
            {
                return SQLDBInfo.Instance.GetDatabases(connectionString);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(LogType.BusinessLayer, LogLevel.Error, ex.ToString());
                return null;
            }
        }

        /// <summary>
        /// Gets the functions.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <returns></returns>
        public List<Function> GetFunctions(string connectionString)
        {
            try
            {
                return SQLDBInfo.Instance.GetFunctions(connectionString);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(LogType.BusinessLayer, LogLevel.Error, ex.ToString());
                return null;
            }
        }

        /// <summary>
        /// Gets the stored procedures.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <returns></returns>
        public List<StoredProcedure> GetStoredProcedures(string connectionString)
        {
            try
            {
                return SQLDBInfo.Instance.GetStoredProcedures(connectionString);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(LogType.BusinessLayer, LogLevel.Error, ex.ToString());
                return null;
            }
        }

        /// <summary>
        /// Gets the tables.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <returns></returns>
        public List<Table> GetTables(string connectionString)
        {
            try
            {
                return SQLDBInfo.Instance.GetTables(connectionString);

            }
            catch (Exception ex)
            {
                Logger.WriteLog(LogType.BusinessLayer, LogLevel.Error, ex.ToString());
                return null;
            }
        }

        /// <summary>
        /// Gets the views.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <returns></returns>
        public List<View> GetViews(string connectionString)
        {
            try
            {
                return SQLDBInfo.Instance.GetViews(connectionString);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(LogType.BusinessLayer, LogLevel.Error, ex.ToString());
                return null;
            }
        }

        #endregion Methods
    }
}